//
//  HomeCrowdHelpTAVC.m
//  ioschishan
//
//  Created by 马田成 on 2017/7/17.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "HomeCrowdHelpTAVC.h"

@interface HomeCrowdHelpTAVC ()<UITextViewDelegate, UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *waterTF;
@property (weak, nonatomic) IBOutlet UITextView *contentFV;
@property (weak, nonatomic) IBOutlet UILabel *waterLab;
@property (nonatomic, strong) UILabel *placeHolderLabel;
@end

@implementation HomeCrowdHelpTAVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"帮助详情"];
    self.waterTF.keyboardType = UIKeyboardTypeNumberPad;
    self.placeHolderLabel = [[UILabel alloc] init];
    
    self.waterTF.delegate = self;
    
    self.placeHolderLabel.numberOfLines = 0;
    self.placeHolderLabel.font = [UIFont systemFontOfSize:13];
    self.placeHolderLabel.textColor = getColor(@"9B9B9B");
    [self.placeHolderLabel sizeToFit];
    self.placeHolderLabel.text = @"跟小伙伴说一句话吧～";
    self.contentFV.delegate = self;
    
    
    [self.contentFV addSubview:self.placeHolderLabel];
    
    [self.contentFV setValue:self.placeHolderLabel forKey:@"_placeholderLabel"];
    
    
    
    // Do any additional setup after loading the view from its nib.
}
//确认捐款

- (IBAction)comfindClick:(UIButton *)sender {
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    //    NSString *str = @"917b0ddccade4345b1b066fdc4971a14";
    
    [productParams setValue:token forKey:@"token"];
    [productParams setValue:_crowd_id forKey:@"crowd_id"];
    [productParams setValue:self.waterTF.text forKey:@"money"];
    [productParams setValue:self.contentFV.text forKey:@"content"];
    
    [[MNetworkHandler sharedInstance]conURL:home_CrowdCrowdcrowdSupport networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            [self.navigationController popViewControllerAnimated:YES];
            

        }
        
        else {

            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];

            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
    }];

    
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    self.waterLab.text = [self.waterTF.text stringByAppendingString:string];
    
    if (textField == _waterTF) {
        
        if (string.length == 0) return YES;
        
        NSInteger existedLength = textField.text.length;
        NSInteger selectedLength = range.length;
        NSInteger replaceLength = string.length;
        
        if (existedLength - selectedLength + replaceLength > 11) {
            return NO;
        }
    }

    
    return YES;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
